/*
 * @lc app=leetcode.cn id=7 lang=cpp
 *
 * [7] 整数反转
 */
#include "include.h"
// @lc code=start
class Solution {
public:
    int reverse(int x) {
        int rev = 0;
        while (x != 0) {
            if (rev < INT_MIN / 10 || rev > INT_MAX / 10) {
                return 0;
            }
            int digit = x % 10;
            x /= 10;
            rev = rev * 10 + digit;
        }
        return rev;
        
/**        
        // bool minusFlag = x < 0;

        int mod;
        std::vector<int> number;
        while (x != 0){
            mod =  x%10;
            number.emplace_back(mod);
            x = x/10;
        }

        int n = number.size();

        long int multi = 1;
        long int res = 0;

        for (int i=n-1;i>=0;--i){
            res += multi * number[i];
            if (res > INT32_MAX){return 0;}
            multi *= 10;
        }

        // if (minusFlag){return -res;}

        return res;
*/        
    }
};
// @lc code=end

